using LiJ.Pay.WeiXin.Pay.Mos;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;

namespace LiJ.Pay.WeiXin.Pay
{
	public class WxPayRefundApi : WxPayBaseApi
	{
		public WxPayRefundApi(WxPayCenterConfig config = null)
			: base(config)
		{
		}

		/// <summary>
		///  申请退款接口 【需要证书】
		/// </summary>
		/// <param name="refundReq"></param>
		/// <returns></returns>
		public async Task<WxPayRefundResp> RefundOrderAsync(WxPayRefundReq refundReq)
		{
			SortedDictionary<string, object> dics = refundReq.GetDics();
			string addressUrl = "https://api.mch.weixin.qq.com" + "/secapi/pay/refund";
			HttpClient certHttpClient = base.GetCertHttpClient();
			return await base.PostApiAsync(addressUrl, dics, (Func<HttpResponseMessage, Task<WxPayRefundResp>>)null, certHttpClient, (Action<SortedDictionary<string, object>>)null);
		}

		/// <summary>
		/// 退款查询接口
		/// </summary>
		/// <param name="refundReq"></param>
		/// <returns></returns>
		public async Task<WxPayGetRefundResp> QueryRefundAsync(WxPayRefundReq refundReq)
		{
			SortedDictionary<string, object> dics = refundReq.GetDics();
			string addressUrl = "https://api.mch.weixin.qq.com" + "/pay/refundquery";
			return await base.PostApiAsync(addressUrl, dics, (Func<HttpResponseMessage, Task<WxPayGetRefundResp>>)null, (HttpClient)null, (Action<SortedDictionary<string, object>>)null);
		}

		/// <summary> 
		///  关闭统一下单订单
		/// 请不要和扫码撤销订单搞混
		/// </summary>
		/// <param name="out_trade_no"></param>
		/// <returns></returns>
		public async Task<WxPayBaseResp> CloseUniOrderAsync(string out_trade_no)
		{
			string addressUrl = "https://api.mch.weixin.qq.com" + "/pay/closeorder";
			SortedDictionary<string, object> dics = new WxPayBaseReq().GetDics();
			dics["out_trade_no"] = out_trade_no;
			return await base.PostApiAsync(addressUrl, dics, (Func<HttpResponseMessage, Task<WxPayQueryOrderResp>>)null, (HttpClient)null, (Action<SortedDictionary<string, object>>)null);
		}

		/// <summary>
		///  撤销刷卡订单API，【需要证书】
		/// </summary>
		/// <param name="transaction_id">微信订单号 二选一 String(32) 微信的订单号，建议优先使用</param>
		/// <param name="out_trade_no"> 商户订单号 String(32)</param>
		/// <returns></returns>
		public async Task<WxPayResverOrderResp> ReverseMicroOrderAsync(string transaction_id, string out_trade_no)
		{
			string addressUrl = "https://api.mch.weixin.qq.com" + "/secapi/pay/reverse";
			SortedDictionary<string, object> dics = new WxPayBaseReq().GetDics();
			dics["out_trade_no"] = out_trade_no;
			dics["transaction_id"] = transaction_id;
			return await base.PostApiAsync(addressUrl, dics, (Func<HttpResponseMessage, Task<WxPayResverOrderResp>>)null, base.GetCertHttpClient(), (Action<SortedDictionary<string, object>>)null);
		}
	}
}
